package com.ttn.common.core.exception;

public class Exceptions {

    public static void throwException(ErrorType errorType) {
        if (errorType != null){
            throw new BaseException(errorType, errorType.getMsg());
        }
        throw new BaseException();
    }

    public static void throwException(String code, String msg) {
        throw new BaseException(code, msg);
    }

    public static void throwException(String msg) {
        throw new BaseException("00000000", msg);
    }

    /**
     * 判断表达式不为true，报异常
     * @param expression
     * @param errorType
     */
    public static void assertTrue(boolean expression, ErrorType errorType) {
        if(!expression) {
            throwException(errorType);
        }
    }

    /**
     * 判断表达式不为true，报异常
     * @param expression
     * @param code
     * @param msg
     */
    public static void assertTrue(boolean expression, String code, String msg) {
        if(!expression) {
            throwException(code, msg);
        }
    }

    /**
     * 判断表达式不为true，报异常
     * @param expression
     * @param msg
     */
    public static void assertTrue(boolean expression, String msg) {
        if(!expression) {
            throwException(msg);
        }
    }
}
